// Device/pages/Info/components/band-component/index.js
import { customNavigate } from '@/utils/route'
const app = getApp();
Component({
    /**
     * 组件的初始数据
     */
    data: {
        STATIC_PREFIX: app.globalData.STATIC_PREFIX,
        healthList: []
    },
    /**
     * 组件的属性列表
     */
    properties: {
        deviceInfo: {
            type: Object,
            value: {}
        }
    },
    observers: {
        deviceInfo(value) {
            const health_map = new Map([
                ['heartrate', '心率'],
                ['sdbp', '血压'],
                ['bloodoxygen', '血氧'],
                ['step', '计步'],
                ['temperature', '体温'],
                ['sleep', '睡眠']
            ]);
            const tagMappings = new Map([
                ['heartrate', 'heartrate'],
                ['sdbp', 'bp'],
                ['step', 'stepsum'],
                ['bloodoxygen', 'bloodoxygen'],
                ['temperature', 'temperature'],
                ['sleep', 'sleep']
            ])
            let obj = {
                heartrate: value['heartrate'],
                sdbp: value['sdbp'],
                bloodoxygen: value['bloodoxygen'],
                temperature: value['temperature'],
                sleep: value['sleep'],
                step: value['step']
            }
            if(value.product_type == 'TWC1') {
                delete obj.sdbp;
                delete obj.sleep;
            }
            let result = [];
            for (let [key, value] of Object.entries(obj)) {
                result.push({
                    key: health_map.get(key),
                    value,
                    tag: tagMappings.get(key)
                })
            }
            this.setData({
                healthList: result
            })
        }
    },



    /**
     * 组件的方法列表
     */
    methods: {
        onDeviceInfoChange(newVal, oldVal) {
        },
        onNavigate(e) {
            const { item } = e.currentTarget.dataset;
            // if(item.key == '睡眠') return;
            customNavigate({
                url: '/Health/pages/Sub/index',
                params: {
                    tag: item.tag
                }
              })
        }
    }
})